#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const ll mod = 998244353;
const ll N =5e5+10;

ll a[N],f[N],sum[N],n,q;
void solve()
{
    cin >> n >> q;
    for(ll i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for(ll i=n;i>=1;i--)
    {
        sum[i] = (sum[i + 1] + a[i])%mod;
    }
    for(ll i=n;i>=1;i--)
    {
        f[i] = (sum[i] + f[i + 1])%mod;
    }
    while(q--)
    {
        ll l,r;
        cin >> l >> r;
        ll x = (f[l] - f[r + 1]+mod)%mod;
        ll ans=(x-(r-l+1)*sum[r+1]%mod+mod)%mod;
        cout << ans << endl;
    }
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
